import 'package:dirver/widgets/common_image.dart';
import 'package:flutter/material.dart';

class ItemWidgetData {
  final String title;
  final String subTitle;
  final String source;
  final String imgUrl;
  final String createTime;
  final String id;

  ItemWidgetData({required this.title,required this.subTitle,required this.source,required this.imgUrl,required this.createTime,required this.id});
}

class ItemWidget extends StatelessWidget {
  final ItemWidgetData data;

  const ItemWidget({Key? key,required this.data}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return InkWell(
      // 点击跳转到详情页，携带路径参数 id（与 Routes.detail = '/detail/:id' 对应）
      onTap: () => Navigator.pushNamed(context, '/detail/${data.id}'),
      child: Container(
        // 统一行高，便于右侧 Column 上下分布
        // constraints: BoxConstraints(minHeight: 90),
        // 底部分割线（灰色）
        decoration: BoxDecoration(
          border: Border(
            bottom: BorderSide(color: Colors.grey[300]!, width: 0.5),
          ),
        ),
        padding: EdgeInsets.symmetric(horizontal: 10,vertical: 5),
        child: Row(
          children: [
            // 左侧固定高的缩略图
            CommonImage(src: data.imgUrl,width: 120,height: 80,fit: BoxFit.cover,),
            // 注意：无子节点的 Padding 宽度为 0，这里应使用 SizedBox 产生间距
            SizedBox(width: 10),
            // 关键：为 Column 指定确定的高度（与左侧图片一致），让 spaceBetween 有效分配上下空间
            Expanded(
              child: SizedBox(
                height: 70,
                child: Column(
                  // 左右对齐到起始位置
                  crossAxisAlignment: CrossAxisAlignment.start,
                  // 上下两端分布
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    // 避免标题过长挤压底部信息行，影响上下两端分布的视觉效果
                    Text(
                      data.title,
                      textAlign: TextAlign.left,
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                      style: TextStyle(fontSize: 14,color: Colors.black,fontWeight: FontWeight.w400 ),
                    ),
                    Text(
                      data.subTitle,
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                      style: TextStyle(fontSize: 12,color: Colors.black45),),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text(data.source,style: TextStyle(fontSize: 12,color: Colors.black45),),
                        Text(data.createTime,style: TextStyle(fontSize: 12,color: Colors.black45),),
                      ],
                    )
                  ],
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}